/* eslint-disable @typescript-eslint/no-var-requires */
const { merge } = require('webpack-merge');
const tsImportPluginFactory = require('ts-import-plugin');
const vConsolePlugin = require('vconsole-webpack-plugin');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');

module.exports = {
  productionSourceMap: process.env.NODE_ENV !== 'production',
  devServer: {
    // 端口号
    port: 3030,
    proxy: {
      '/cxf': {
        target: 'http://202.103.135.130:40022/crPatient',
      },
    },
  },
  configureWebpack: (config) => {
    const debug = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'development';
    let pluginsDev = [
      new vConsolePlugin({
        filter: [],
        enable: debug,
      }),
    ];
    config.plugins = [...config.plugins, ...pluginsDev];
  },
  chainWebpack: (config) => {
    config.module
      .rule('ts')
      .use('ts-loader')
      .tap((options) => {
        options = merge(options, {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [
              tsImportPluginFactory({
                libraryName: 'vant',
                libraryDirectory: 'es',
                style: true,
              }),
            ],
          }),
          compilerOptions: {
            module: 'es2015',
          },
        });
        return options;
      });
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          autoprefixer(),
          pxtorem({
            rootValue: 37.5,
            propList: ['*'],
            selectorBlackList: ['.van-'], //忽略vant-开头的class vant库的ui转换
            exclude: /node_modules/i, // 过滤掉node_modules 文件夹下面的样式
            mediaQuery: false, //媒体查询( @media screen 之类的)中不生效
            minPixelValue: 12, //px小于12的不会被转换
          }),
        ],
      },
    },
  },
};
